﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LuoFangeEvalTeacher.aspx.cs" Inherits="TeacherEval_Student_CauseTeacherEval_LuoFangeEvalTeacher" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <link href="../../Common/css/main.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="../../Common/js/jquery.js"></script>
    <script type="text/javascript" src="../../Common/js/common.js"></script>
    <script type="text/javascript" src="../../Common/js/jsUtil.js"></script>
    <script type="text/javascript" src="../../../../Common/js/ScoreInputUtil.js"></script>
    <script type="text/javascript" src="../../../Common/js/TableForExport.js"></script>
    <script type="text/javascript">
    // 保存本次结果
        function saveList() {
            var list = [];
            var trList = $("#tbResult tr");
            var stuJsonList = "";
            var jsonList = "";
            var stuList = [];
            for (var i=0; i<trList.length; i++) {
                if(trList[i].getAttribute("itemID") == null)
                    continue;
                    
                var itmeID = parseInt(trList[i].getAttribute("itemID"));
                var teacherID = parseInt(trList[i].getAttribute("teachID"));
                var inputList = $(trList[i]).find("input");
                var inputState = false;
                
                var param = -1;
                var score = 1;
                var operator = 1;
                var type = 1;
                for (var j=0; j<inputList.length; j++) {
                    if(j==0 && inputList[j].checked) {
                        param = 1;
                    }
                    else if(inputList[j].checked) {
                        param = 0;
                    }
                }

                if (param == -1) {
                    showMassgeBox("注意", "请填写完整");
                    return false;
                }
                inputState = true;

                if (isNaN(operator)) operator = "0";
                var item = "{\"MoralityItemID\": "+itmeID+", \"TeacherID\": "+teacherID+", \"Param\": "+param+", \"Score\": "+score+", \"Type\": "+type+", \"Operator\": "+operator+"}";
                stuList.push(item);
                //} 
                
            }
            var remarkList = $(trList[trList.length-1]).find("input");
            /* 填写了该学生的资料 */
            if (inputState) {
                stuJsonList = stuList.join(",");
                stuJsonList = "{\"TeacherID\": "+teacherID+",\"TeacherItems\":[" + stuJsonList + "]";
                if (remarkList.length > 0 && remarkList[0].value != "") stuJsonList += ", \"Remark\": \"" + remarkList[0].value + "\"";
                stuJsonList += "}";
                list.push(stuJsonList);
            }
            /* 只填了备注 */
            else {
                if (remarkList.length > 0 && remarkList[0].value != "") {
                    studentID = parseInt(remarkList[0].id.replace("span_",""));
                    stuJsonList = "{\"TeacherID\": "+teacherID+",\"Remark\": \"" + remarkList[0].title + "\"}";
                    list.push(stuJsonList);
                }
            }
                
            if (stuJsonList.length > 0) {
                jsonList = list.join(",");
                jsonList = "[" + jsonList + "]";
            }
            var schoolYear = "<%=SchoolCommon.Sch_SchoolInfo.SchoolYear %>";//request("SchoolYear");
            if (schoolYear == "") schoolYear = -1;
            else schoolYear = parseInt(schoolYear);
            
            var term = "<%=SchoolCommon.Sch_SchoolInfo.SchoolTerm %>";
            if (term == "") term = -1;
            else term = parseInt(term);
            
            var year = request("Year");
            if (year == "") year = -1;
            else year = parseInt(year);
            
            var month = request("Month");
            if (month == "") month = -1;
            else month = parseInt(month);
            
            PageMethods.SaveScoreInput(parseInt(request("HistoryId")),jsonList, schoolYear, term, year, month,
                function(succ){ 
                    if (succ) 
                    {
                        showMassgeBox("保存成功","保存成功"); 
//                        var leftFrame = this.parent.frames["leftFrame"];
//                        var btnReload = leftFrme.btnReload;
//                        btnReload.click();
                    this.parent.frames['leftFrame'].document.getElementById('btnReload').click();
                    }
                    else
                    {
                        showMassgeBox("保存失败","保存失败, 请检查数据是否录入或者录入的数据是否符合规则."); 
                    }
                 }, 
                function(err){return;}
            );
        }
    </script>
</head>
<body style="width: 98%; margin: auto;padding-left:5px;">
   <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <div class="mainWarp">
            <div style="margin-top: 5px;">
                <h2>
                    <%= ReportTitle %>
                </h2>
                <br/>
            </div>            
            <input type="button" class="commonBut" id="btnSave" value="保存" onclick="saveList();" />

                    <asp:Table CssClass="useList" ID="tbResult" runat="server">
                    </asp:Table>
            <br />
        </div>
    </form>
</body>

</html>